
#include "stdafx.h"
#include "doc_plugin_interface.h"
#include "wf_getselect.h"
#include "wf_selectsingle.h"

#include "pf_snapper.h"


WF_GetSelect::WF_GetSelect(PF_Container& container,
                                 PF_GraphicView& graphicView)
        :PF_ActionInterface("Get Select", container, graphicView) {
    completed = false;
    mesage = tr("Select objects:");
}


void WF_GetSelect::updateMouseButtonHints() {
    switch (getStatus()) {
    case Select:
        PF_DIALOGFACTORY->updateMouseWidget(mesage, tr("Cancel"));
            break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}


void WF_GetSelect::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::SelectCursor);
}

void WF_GetSelect::setMesage(QString msg){
    mesage = msg;
}


void WF_GetSelect::init(int status) {
        PF_ActionInterface::init(status);
        graphicView->setCurrentAction(
                new WF_SelectSingle(*container, *graphicView));
}



void WF_GetSelect::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        completed = true;
    }
}



void WF_GetSelect::updateToolBar() {
    if (PF_DIALOGFACTORY!=NULL) {
        if (!isFinished()) {
            PF_DIALOGFACTORY->requestToolBarSelect(this, LX_Define::ActionDefault);
        } else {
            PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarMain);
            PF_DIALOGFACTORY->updateMouseWidget("", "");
            completed = true;
        }
    }
}

/**
 * Adds all selected entities from 'container' to the selection.
 */
void WF_GetSelect::getSelected(QList<Plug_Entity *> *se) {
    for (PF_Entity* e= container->firstEntity();
            e!=NULL; e= container->nextEntity()) {

        if (e->isSelected()) {
            Plugin_Entity *pe = new Plugin_Entity(e);
            se->append(reinterpret_cast<Plug_Entity*>(pe));
        }
    }
}


// EOF
